var express = require('express');
var router = express.Router();

const setting = common => {
  // 一般是 get/post (我就都写了)
  router.get('/', function (req, res, next) {
    res.type('json');
    console.log('get')
    common(req, res, next, 'get');
  });

  router.post('/', function (req, res, next) {
    res.type('json');
    console.log('post')
    common(req, res, next, 'post')
  });

  router.put('/', function (req, res, next) {
    res.type('json');
    console.log('put')
    common(req, res, next, 'put')
  });

  router.delete('/', function (req, res, next) {
    res.type('json');
    console.log('delete')
    common(req, res, next, 'delete')
  });

  router.head('/', function (req, res, next) {
    res.type('json');
    console.log('options')
    common(req, res, next, 'head')
  });

  router.options('/', function (req, res, next) {
    res.type('json');
    console.log('options')
    common(req, res, next, 'options')
  });

  // 有问题
  // router.patch('/', function (req, res, next) {
  //   res.type('json');
  //   console.log('options')
  //   common(req, res, next, 'patch')
  // });
}

module.exports = {
  router,
  setting,
};